//
//  FCTImgBLabelView.m
//  commonUse
//
//  Created by WJC on 2018/11/21.
//

#import "FCTImgBLabelView.h"
#import "UIImageView+WJCDownload.h"
#import "WJCDefine.h"
@implementation FCTImgBLabelView
static UIImage *placeHelderImg;
-(instancetype)initWithTagFrame:(CGRect)frame andImage:(id)Image andName:(NSString *)label andHiddenClose:(BOOL)hiddenClose{
    if (self=[super initWithFrame:frame]) {
//        CGFloat width=0.0f;
//        if (frame.size.width<frame.size.height) {
//            width=frame.size.width-10;
//
//        }else{
//            width=frame.size.height-10;
//        }
        self.imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 10, frame.size.width, frame.size.height-8)];
        self.imageView.userInteractionEnabled=YES;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
        [self.imageView addGestureRecognizer:tap];
        if ([Image isKindOfClass:[UIImage class]]) {
            self.imageView.image=Image;
        }else{
            [self.imageView fc_setImageWithURL:[NSString stringWithFormat:@"%@",Image] placeholder:placeHelderImg?placeHelderImg:[WJCDeployModel getDeployWithDeployKey:WJCDeployHeadImage] completed:nil];
        }
        [self addSubview:_imageView];
        
        if (!hiddenClose) {
            self.closeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            self.closeBtn.frame=CGRectMake(frame.size.width-35, 10, 35, 35);
//            [self.closeBtn setImage:commonUseImageName(@"ic_delete_little") forState:UIControlStateNormal];
            [self.closeBtn addTarget:self action:@selector(closeClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.closeBtn];
        }
            self.label=[[UILabel alloc] initWithFrame:CGRectMake(0, self.imageView.y+self.imageView.height-20, self.imageView.width, 20)];
            self.label.textAlignment=NSTextAlignmentCenter;
            self.label.text=label;
        self.label.backgroundColor=WJCARGBColor(70, 148, 255, 125);
        self.label.textColor=[UIColor whiteColor];
        self.label.font=font12;
        
        self.label.userInteractionEnabled=YES;
        UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap1:)];
        [self.label addGestureRecognizer:tap1];
            [self addSubview:_label];
        }
    return self;
}
+(void)setPlaceImageWithImg:(UIImage *)img{
    placeHelderImg=img;
}
-(instancetype)initWithFrame:(CGRect)frame andImage:(id)Image andName:(NSString *)label andHiddenClose:(BOOL)hiddenClose{
    if (self=[super initWithFrame:frame]) {
        CGFloat width=0.0f;
        if (frame.size.width<frame.size.height) {
            width=frame.size.width-10;
            
        }else{
             width=frame.size.height-10;
        }
        self.imageView=[[UIImageView alloc] initWithFrame:CGRectMake(5, 0, width, width)];
        self.imageView.userInteractionEnabled=YES;
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
        [self.imageView addGestureRecognizer:tap];
        if ([Image isKindOfClass:[UIImage class]]) {
            self.imageView.image=Image;
        }else{
            [self.imageView fc_setImageWithURL:[NSString stringWithFormat:@"%@",Image] placeholder:placeHelderImg?placeHelderImg:[WJCDeployModel getDeployWithDeployKey:WJCDeployHeadImage] completed:nil];
        }
          [self addSubview:_imageView];
        
        if (!hiddenClose) {
            self.closeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            self.closeBtn.frame=CGRectMake(frame.size.width-20, 0, 20, 20);
//            [self.closeBtn setImage:commonUseImageName(@"album_delete_photos") forState:UIControlStateNormal];
            [self.closeBtn addTarget:self action:@selector(closeClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.closeBtn];
        }
        if(label){
            self.label=[[UILabel alloc] initWithFrame:CGRectMake(0, self.imageView.y+self.imageView.height, frame.size.width, 20)];
            self.label.textAlignment=NSTextAlignmentCenter;
            self.label.text=label;
            self.label.font=font12;
            [self addSubview:_label];
        }else{
            self.imageView.y+=10;
            self.closeBtn.y+=8;
        }
        
    }
    return self;
}
-(void)closeClick:(UIButton*)sender{
    if ([self.btnDelegate respondsToSelector:@selector(TImgBLabelcloseBtnClickWithButton:AndSuperView:)]) {
        [self.btnDelegate TImgBLabelcloseBtnClickWithButton:sender AndSuperView:self];
    }
}
-(void)tap:(UITapGestureRecognizer*)sender{
    if ([self.ImgDelegate respondsToSelector:@selector(TImgBLabelimageWithTap:AndSuperView:)]) {
        [self.ImgDelegate TImgBLabelimageWithTap:sender AndSuperView:self];
    }else{
        
//        FCImageShowBrowser *browser=[FCImageShowBrowser shareBrowser];
//        browser.ImagesArr=[NSMutableArray arrayWithObject:((UIImageView*)sender.view).image];
//        browser.currentPage=sender.view.tag;
//        browser.clickImageView=sender.view;
//        browser.currentControllerView=self.viewController.view;
//        [browser showView];
    }
}
-(void)tap1:(UITapGestureRecognizer*)sender{
    if ([self.ImgDelegate respondsToSelector:@selector(TImgBLabelbottomTagLabelTap:AndSuperView:)]) {
        [self.ImgDelegate TImgBLabelbottomTagLabelTap:sender AndSuperView:self];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
